package com.taotao.controller;

import com.taotao.common.pojo.BaseResult;
import com.taotao.common.utils.Constants;
import com.taotao.common.utils.DateUtil;
import com.taotao.mapper.EyParamMapper;
import com.taotao.pojo.EyParam;
import com.taotao.pojo.EyParamExample;
import com.taotao.pojo.EyPicture;
import com.taotao.pojo.EyPictureExample;
import com.taotao.service.MenuService;
import com.taotao.service.ParamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/param")
public class ParamController {
	private static final Logger logger = LoggerFactory.getLogger(ParamController.class);

	@Autowired
	ParamService paramService;
	@Autowired
	EyParamMapper eyParamMapper;
	
	@RequestMapping("/api/openSwitch")
	@ResponseBody
	public Map<String,Object>  getMenuList(HttpServletRequest request) {
		String isOpen=request.getParameter("isOpen");
		String isPayPlatform_goods="";
		String secCheck="";
		String serviceTypeShow="";
		if(Constants.true_string.equals(isOpen)){
			isPayPlatform_goods=Constants.num_1;
			secCheck=Constants.false_string;
			serviceTypeShow="House|Buy&Sell|Move|Ayi|Repair|Plumber|Satellite|Locksmith";
		}else{
			isPayPlatform_goods=Constants.num_0; //发布时不可以支付
			secCheck=Constants.true_string;  //发布时校验
			serviceTypeShow="House|Buy&Sell|Move|Ayi|Repair|Plumber|Satellite";
		}

		List<String> paramKeys=new ArrayList<>();
		paramKeys.add(Constants.isPayPlatform_goods);
		paramKeys.add(Constants.secCheck);
		paramKeys.add(Constants.serviceTypeShow);

		EyParamExample example= new EyParamExample();
		EyParamExample.Criteria criteria= example.createCriteria();
		criteria.andParamKeyIn(paramKeys);
		List<EyParam> listParam = eyParamMapper.selectByExample(example);
		for(EyParam param:listParam){
			if(param.getParamKey().equals(Constants.isPayPlatform_goods)){
				param.setParamValue(isPayPlatform_goods);
			}
			if(param.getParamKey().equals(Constants.secCheck)){
				param.setParamValue(secCheck);
			}
			if(param.getParamKey().equals(Constants.serviceTypeShow)){
				param.setParamValue(serviceTypeShow);
			}
			param.setUpdateTime(DateUtil.getDateAndTime());
			eyParamMapper.updateByPrimaryKeySelective(param);
		}

		return BaseResult.getSuccMap();
	}
	
	
}
